﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Hsmp.SocietyAdmin.Entity;
using Hsmp.SocietyAdmin.DataAccess;
using Hsmp.SocietyAdmin.IBusinessLogic;

namespace Hsmp.SocietyAdmin.BusinessLogic
{
    public class FlatRegistrationBus : IFlatRegistrationBus
    {
        #region  Variable& constant
        #endregion  Variable& constant

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Properties
        #endregion Properties

        #region Public Methods
        #region IFlatRegistrationBus Members

        public bool RegisterNewFlat(Flat FlatEntity)
        {
            bool IsOperationSuccessful = false;
            try
            {
                FlatDao lFlatDao = new FlatDao();
                IsOperationSuccessful = lFlatDao.Insert(FlatEntity);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
            return IsOperationSuccessful;
        }

        public bool UpdateRegisteredFlat(Flat FlatEntity)
        {
             bool IsOperationSuccessful = false;

            try
            {
                FlatDao lFlatDao = new FlatDao();
                IsOperationSuccessful=lFlatDao.Update(FlatEntity);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
            return IsOperationSuccessful;
        }

        public Flat GetSelectedFlatByFlatKey(string FlatKey)
        {
            try
            {
                FlatDao lFlatDao = new FlatDao();
                Flat lFlat;
                lFlat = lFlatDao.GetByID(FlatKey);
                if (lFlat == null)
                {
                    return null;
                }
                else
                {
                    return lFlat;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            } 
        }

        public List<Flat> GetAllFlatList()
        {
            List<Flat> lFlatList = new List<Flat>();
            try
            {
                FlatDao IFlatDao = new FlatDao();
                lFlatList = IFlatDao.GetAll();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print(ex.Message);
                throw ex;
            }
            return lFlatList;
        }
        
        #endregion
        #endregion Public Methods

        #region Events
        #endregion Events

        #region Private Methods
        #endregion Private Methods

    }
}
